<div class="jjzbk" style="height: 100%;width:100%;overflow:auto;">
    <div class="button-group-head" style="">
        <span class="hrp-btn hrp-btn-add" id="openDialog"><i class="fa fa-plus" style="padding-right: 4px;"></i>添加</span>
        <span  class="hrp-btn hrp-btn-refresh"><i class="fa fa-refresh" style="padding-right: 4px;"></i>刷新</span>
    </div>
    <!--<div class="jjzbk-toolbar">-->
        <!--<span style="padding-top: 4px;height: 40px;float: right;padding-right: 20px;">-->
            <!--<input id="cc" name="dept">-->
        <!--</span>-->
        <!--<span style="height:40px;line-height: 40px;float: right;padding-right: 5px;font-size:14px;">指标类别:</span>-->
    <!--</div>-->
    <div>
        <table id="dg" class="easyui-datagrid" style="width:100%;">
            <!--<thead>-->
            <!--<tr>-->
            <!--<th  width="15%">Item ID(15%)</th>-->
            <!--<th  width="15%">Product(15%)</th>-->
            <!--<th  width="15%">List Price(15%)</th>-->
            <!--<th  width="15%">List Price(15%)</th>-->
            <!--<th width="15%">List Price(15%)</th>-->
            <!--</tr>-->
            <!--</thead>-->
        </table>
    </div>

    <div id="editActionDialog"  class="ss-dialog">
        <span class="ss-dialog-close" style="">X</span>
        <div class="ss-dialog-head" style="">
            添加
        </div>
        <div class="ss-dialog-content">
            <div class="row" style="height: 60px;">
                <input type="hidden" id="idkey" value="-1"/>
                <span style="width:17%;height:60px;line-height:60px;float:left;text-align: center;">指标代码</span>
                <span style="width:33%;float:left;"><input disabled="disabled" id="id" type="text" value="0" style="margin: 0;padding: 0;height:35px;margin-top:10px;border:1px solid #ccc;box-shadow: 1px 1px 1px #eee;width:100%;" /></span>
                <span style="width:17%;height:60px;line-height:60px;float:left;text-align: center;">指标名称</span>
                <span style="width:33%;float:left;"><input type="text"  id="jjmc" style="margin: 0;padding: 0;height:35px;margin-top:10px;border:1px solid #ccc;box-shadow: 1px 1px 1px #eee;width:100%;" placeholder="输入指标名称" /></span>
            </div>
            <div class="row" style="height: 60px;">
                <span style="width:17%;height:60px;line-height:60px;float:left;text-align: center;">默认值</span>
                <span style="width:33%;float:left;"><input id="defaultValue" type="text" value="0" style="margin: 0;padding: 0;height:35px;margin-top:10px;border:1px solid #ccc;box-shadow: 1px 1px 1px #eee;width:100%;" /></span>
                <span style="width:17%;height:60px;line-height:60px;float:left;text-align: center;">考核科室</span>
                <span style="width:33%;float:left;padding-top: 21px;font-size: 14px;cursor: pointer;">
                    <!--<input type="checkbox" value="1" class="khkslb" name="khkslb" id="lc" /><label for="lc"> 临床</label>-->
                    <!--<input type="checkbox" value="2" class="khkslb" name="khkslb" id="hl" /><label for="hl"> 护理</label>-->
                    <!--<input type="checkbox" value="3" class="khkslb" name="khkslb" id="yj"/> <label for="yj">医技</label>-->
                    <span class="self-checkbox" id="lc" data-value="1"><i class="fa fa-square-o"></i>临床</span>
                    <span class="self-checkbox" id="hl" data-value="2"><i class="fa fa-square-o"></i>护理</span>
                    <span class="self-checkbox" id="yj" data-value="3"><i class="fa fa-square-o"></i>医技</span>
                </span>
            </div>
            <div class="row" style="height: 60px;">
                <span style="width:17%;height:60px;line-height:60px;float:left;text-align: center;">停用标志</span>
                <span style="width:33%;float:left;padding-top: 21px;font-size: 14px;cursor: pointer;">
                    <!--<input type="radio" value="1" class="tybz" name="tybz" id="qy" checked="true"/><label for="qy"> 启用</label>-->
                    <!--<input type="radio" value="0" class="tybz" name="tybz" id="ty" /><label for="ty"> 停用</label>-->

                    <span class="self-radio" data-radio="true" id="qy" data-value="1"><i class="fa fa-dot-circle-o"></i>启用</span>
                    <span class="self-radio" id="ty" data-value="0"><i class="fa fa-circle-o"></i>停用</span>
                </span>
                <span style="width:17%;height:60px;line-height:60px;float:left;text-align: center;"></span>
                <span style="width:33%;float:left;"></span>
            </div>
        </div>
        <div  class="ss-dialog-head" style="">

            <span class="hrp-btn hrp-btn-delete" style="float: right;" id="btn-cancel"><i class="fa fa-close" style="padding-right: 4px;"></i>取消</span>
            <span class="hrp-btn hrp-btn-add" style="float: right;" id="btn-save"><i class="fa fa-plus" style="padding-right: 4px;"></i>添加</span>
        </div>
    </div>
    <div id="mask-model" class="mask-model" style=""></div>


</div>


<script type="text/javascript">

    var dHeight = $(".jjzbk").height()-42;

    var UserIndexPage={
        init:function () {

            this.initGrid();

            this.initEvnets();
            //this.initZblb();
            this.initEditCombox();
        },
        initEvnets:function () {

            var that = this;

            $(window).resize(function () {
                $('#dg').datagrid("resize")
            })

            $("#openDialog").on("click",function () {
                $("#idkey").val("-1");
                $.post("jjfact/getJjfactId",function (result) {
                    if(result.status==200){
                        $("#id").val(result.data);
                    }

                })
                $('#editActionDialog').slideDown(300);
                $("#mask-model").slideDown(300);
            })

            $(".ss-dialog-close").on("click",function () {
                $('#editActionDialog').slideUp(300);
                $("#mask-model").slideUp(300);
            })

            $("#btn-save").on("click",function () {
                that.saveData();
            })

            $("#btn-cancel").on("click",function () {
                $('#editActionDialog').slideUp(300);
                $("#mask-model").slideUp(300);
            })

            //修改
            $(".jjzbk").on("click",".btn-edit",function () {
                var id = $(this).attr("data-id");
                var jjmc = $(this).attr("data-jjmc");
                var value = $(this).attr("data-value");
                var khkslb = $(this).attr("data-khkslb");

                $("#idkey").val(id);
                $("#id").val(id);
                $("#jjmc").val(jjmc);
                $("#defaultValue").val(value);

                //$(".self-radio[data-value='"+tybz+"']").click();
                var khkslbArr = khkslb.split(",");
                $(".self-checkbox").attr("data-checked","false").children("i").removeClass("fa-check-square").addClass("fa-square-o");

                for(var i=0;i<khkslbArr.length;i++){
                    $(".self-checkbox[data-value='"+khkslbArr[i]+"']").click()
                }
                $('#editActionDialog').slideDown(300);
                $("#mask-model").slideDown(300);
                //that.editKhzb()
            })
        },
        initEditCombox:function () {
            var data =[{"id":"0","text":"手工补录","selected":true},{"id":"1","text":"系统采集"}]

            $('#sjly').combobox({
                url:"common/getDicList",
                queryParams: {
                    "id": -1,
                    "lbdm": "2"
                },
                //data:data,
                valueField:'id',
                textField:'text',
                width:200,
                panelHeight:100,
                onSelect:function (record) {
                    //that.initGrid(record.id);
                },
                onLoadSuccess:function () {

                }
            });


            $('#zblb').combobox({
                //url:"jxkhzb/getAllZblb",
                url:"common/getDicList",
                queryParams: {
                    "id": -1,
                    "lbdm": "3"
                },
                valueField:'id',
                textField:'text',
                width:200,
                panelHeight:100,
                onSelect:function (record) {
                    //that.initGrid(record.id);
                },
                onLoadSuccess:function () {

                }
            });
        },
        initEditZblb:function () {


        },
        initZblb:function () {
            var that = this;
            $('#cc').combobox({
                url:"jxkhzb/getAllZblb",
                valueField:'id',
                textField:'text',
                onSelect:function (record) {
                    that.initGrid(record.id);
                },
                onLoadSuccess:function () {

                }
            });
        },
        saveData:function () {
            var id = $("#id").val();
            var jjmc = $("#jjmc").val();
            if ($.trim(jjmc) == "") {
                $.messager.show({title: '提示', msg: '奖金名称不能为空', timeout: 1000, showType: 'slide'});
                return;
            }

            var khkslbArr = $(".self-checkbox[data-checked='true']");
            if (khkslbArr.length == 0) {
                $.messager.show({title: '提示', msg: '请选择所属考核科室', timeout: 1000, showType: 'slide'});
                return;
            }
            var value = $("#defaultValue").val();
            var khkslb = "";
            for (var i = 0; i < khkslbArr.length; i++) {
                if (i < khkslbArr.length - 1) {
                    khkslb += khkslbArr.eq(i).attr("data-value") + ",";
                } else {
                    khkslb += khkslbArr.eq(i).attr("data-value");
                }
            }

            var tybz = $(".self-radio[data-radio='true']").attr("data-value");


            $.post("jjfact/saveJjfactData", {
                "id": id,
                "jjmc": jjmc,
                "khkslb": khkslb,
                "tybz": tybz,
                "value": value,
            }, function (result) {
                if (result.status == 200) {
                    $('#editActionDialog').slideUp(300);
                    $("#mask-model").slideUp(300);
                    $.messager.show({title: '提示', msg: '保存成功', timeout: 1000, showType: 'slide'});
                } else {
                    $.messager.show({title: '提示', msg: '保存失败', timeout: 1000, showType: 'slide'});
                }
            })


        },
        initGrid:function () {
            var data = [];
            $.post("/jjfact/getAllJJfact",function (result) {
                if(result.status==200) {
                    data = result.data;
                }


                $('#dg').datagrid({
                    //url: "jxkhzb/getKhzbListByZblb",
                    data:data,
                    //pagination: true,
                    singleSelect: true,
                    height:dHeight,   //表格高度，可指定高度，可自动
                    //pageNumber: 1,
                    //pageSize: 15,
                    //pageList: [15, 30],
                    //fitColumns:true,
                    loadMsg: "正在加载数据",
                    nowrap: false,
                    striped: true,  //奇偶行是否使用不同的颜色
                    columns:[
                        [
                            {field:'id',title:'编号',width:"20%"},
                            {field:'jjmc',title:'指标名称',width:"30%"},
                            {field:'jjmcpy',title:'拼音',width:"30%"},
                            {
                                field: 'edit', title: '操作', width: "20%",
                                formatter: function (value, row, index) {
                                    return "<a class='btn-edit' href='#' data-id='"+row.id+"'  data-jjmc='"+row.jjmc+"' data-khkslb='"+row.khkslb+"' data-value='"+row.jjvalue+"'>修改</a>"
                                }
                            }
                        ]
                    ]

                });

            })

        }
    }
    $(function () {
        UserIndexPage.init();
    })
</script>